1 <?php
2
3 session_start();
4 require "includes/functions.php";
5 require "includes/db.php";
6 if(!isset($_SESSION['user'])) {
7 header("location: logout.php");
8 }
9
10 $result = "";
11 $pagenum = "";
12 $per_page = 20;
13
14 $count = $db->query("SELECT * FROM food");
15
16 $pages = ceil((mysqli_num_rows($count)) / $per_page);
17
18 if(isset($_GET['page'])) {
19
20 $page = $_GET['page'];
21
22 }else{
23
24 $page = 1;
25
26 }
27
28 $start = ($page - 1) * $per_page;
29
30 $cat = $db->query("SELECT * FROM food LIMIT $start, $per_page");
31
32 if($cat->num_rows) {
33
34 $result = "<table class='table table-hover table-striped'>
35 <thead>
36 <th>S/N</th>
37 <th>Tên món</th>
38 <th>Giá</th>
39 <th>Danh mục</th>
40 <th>Hoạt động</th>
41 </thead>
42 <tbody>";
43
44 $x = 1;
45
46 while($row = $cat->fetch_assoc()) {
47
48 $id = $row['id'];
49 $foodName = $row['food_name'];
50 $foodCat = $row['food_category'];
51 $foodPrice = $row['food_price'];
52 $foodDesc = $row['food_description'];
53
54
55 $result .= "<tr>
56 <td>$x</td>
57 <td>$foodName</td>
58 <td>$foodPrice</td>
59 <td>$foodCat</td>
60 <td><a href='food_list.php?delete=".$id."' onclick='return check();'><i class='pe-7s-close-circle'></i></a></td>
61 </tr>";
62
63
64 $x++;
65 }
66
67 $result .= "</tbody>
68 </table>";
69
70 }else{
71
72 $result = "<p style='color:red; padding: 10px; background: #ffeeee;'>No records available in the database yet</p>";
73
74 }
75
76
77
78
79 if(isset($_GET['delete'])) {
80
81 $delete = preg_replace("#[^0-9]#", "", $_GET['delete']);
82
83 if($delete != "") {
84
85 $sql = $db->query("DELETE FROM food WHERE id='".$delete."'");
86
87 if($sql) {
88
89 echo "<script>alert('Xóa thành công')</script>";
90
91 }else{
92
93 echo "<script>alert('Hoạt động không thành công. Vui lòng thử lại')</script>";
94
95 }
96
97 }
98
99
100 }
101
102
103
104 ?>
105
106 <!doctype html>
107 <html lang="en">
108 <head>
109 <meta charset="utf-8" />
110 <link rel="icon" type="image/png" href="assets/img/favicon.ico">
111 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
112
113 <title>Trà Sữa Hương Vị Thơm - Chuẩn Vị Ngon</title>
114
115 <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
116 <meta name="viewport" content="width=device-width" />
117
118
119 <!-- Bootstrap core CSS -->
120 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
121
122 <!-- Animation library for notifications -->
123 <link href="assets/css/animate.min.css" rel="stylesheet"/>
124
125 <!-- Light Bootstrap Table core CSS -->
126 <link href="assets/css/light-bootstrap-dashboard.css" rel="stylesheet"/>
127
128
129 <!-- CSS for Demo Purpose, don't include it in your project -->
130 <link href="assets/css/demo.css" rel="stylesheet" />
131
132
133 <!-- Fonts and icons -->
134 <link href="assets/css/pe-icon-7-stroke.css" rel="stylesheet" />
135
136
137 <link href="assets/css/style.css" rel="stylesheet" />
138
139 <script>
140
141 function check() {
142
143 return confirm("Are you sure you want to delete this record");
144
145 }
146
147 </script>
148
149 </head>
150 <body>
151
152 <div class="wrapper">
153 <div class="sidebar" data-color="#000" data-image="assets/img/sidebar-5.jpg">
154
155 <!-- you can change the color of the sidebar using: data-color="blue | azure | green | orange | red | purple" -->
156
157
158 <?php require "includes/side_wrapper.php"; ?>
159
160 <div class="main-panel">
161 <nav class="navbar navbar-default navbar-fixed" style="background: #FF5722;">
162 <div class="container-fluid">
163 <div class="navbar-header">
164 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-example-2">
165 <span class="sr-only">Toggle navigation</span>
166 <span class="icon-bar" style="background: #fff;"></span>
167 <span class="icon-bar" style="background: #fff;"></span>
168 <span class="icon-bar" style="background: #fff;"></span>
169 </button>
170 <a class="navbar-brand" href="#" style="color: #fff;">Danh sách trà sữa</a>
171 </div>
172 <div class="collapse navbar-collapse">
173
174 <ul class="nav navbar-nav navbar-right">
175 <li>
176 <a href="logout.php" style="color: #fff;">
177 Thoát
178 </a>
179 </li>
180 </ul>
181 </div>
182 </div>
183 </nav>
184
185
186 <div class="content">
187 <div class="container-fluid">
188 <div class="row">
189 <div class="col-md-12">
190 <div class="card">
191 <div class="header">
192 <h4 class="title">Danh sách trà sữa</h4>
193 </div>
194 <div class="content table-responsive table-full-width">
195
196 <?php echo $result; ?>
197
198 <p style="padding: 0px 20px;"><?php if($pages >= 1 && $page <= $pages) {
199 for($i = 1; $i <= $pages; $i++) {
200 echo ($i == $page) ? "<a href='food_list.php?page=".$i."' style='margin-left:5px; font-weight: bold; text-decoration: none; color: #FF5722;' >$i</a> " : " <a href='food_list.php?page=".$i."' class='btn'>$i</a> ";
201 }
202 } ?></p>
203
204 </div>
205 </div>
206 </div>
207
208 </div>
209 </div>
210 </div>
211
212 <footer class="footer">
213 <div class="container-fluid">
214
215 <p class="copyright pull-right">
216 © 2016 <a href="index.php" style="color: #FF5722;">Trà Sữa Hương Vị Thơm - Chuẩn Vị Ngon - Khơi Nguồn Cảm Hứng</a>
217 </p>
218 </div>
219 </footer>
220
221 </div>
222 </div>
223
224
225 </body>
226
227 <!-- Core JS Files -->
228 <script src="assets/js/jquery-1.10.2.js" type="text/javascript"></script>
229 <script src="assets/js/bootstrap.min.js" type="text/javascript"></script>
230
231 <!-- Checkbox, Radio & Switch Plugins -->
232 <script src="assets/js/bootstrap-checkbox-radio-switch.js"></script>
233
234 <!-- Charts Plugin -->
235 <script src="assets/js/chartist.min.js"></script>
236
237 <!-- Notifications Plugin -->
238 <script src="assets/js/bootstrap-notify.js"></script>
239
240 <!-- Google Maps Plugin -->
241
242 <!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
243 <script src="assets/js/light-bootstrap-dashboard.js"></script>
244
245 <!-- Light Bootstrap Table DEMO methods, don't include it in your project! -->
246 <script src="assets/js/demo.js"></script>
247
248 <script type="text/javascript">
249 $(document).ready(function(){
250
251 /*notice = $("#notify").val();
252
253 //alert(notice);
254
255 demo.initChartist();
256
257 $.notify({
258 icon: 'pe-7s-gift',
259 message: notice
260
261 },{
262 type: 'danger',
263 timer: 7000
264 });
265
266 });*/
267 </script>
268
269 </html>